package blademaster

import (
	"net/http"

	"go-toolkit/library/ecode"
)

// 将大仓封装的 5XX ecode 映射成 HTTP status Code，使业务方可以灵活的在 SLB 平台配置降级策略
func ErrorHTTPStatus(err error) int {
	switch ecode.Cause(err) {
	case ecode.ServerErr, ecode.LimitExceed, ecode.BusinessDegrade:
		return http.StatusInternalServerError
	case ecode.Deadline:
		return http.StatusGatewayTimeout
	case ecode.ServiceUnavailable:
		return http.StatusServiceUnavailable
	default:
		return http.StatusOK
	}
}
